libname dd 'D:\local_c\bfeed3';

**for "Breastfeeding and Children's Early Cognitive Outcomes" REStat;


data x;
infile 'D:\local_c\bfeed3\child08.dat' lrecl=599 missover DSD DLM=' ';
input
  C0000100
  C0000200
  C0003800
  C0003900
  C0004000
  C0004100
  C0004200
  C0004300
  C0004400
  C0004500
  C0004600
  C0004700
  C0004710
  C0004720
  C0004730
  C0004740
  C0004741
  C0004742
  C0004743
  C0004744
  C0004745
  C0004746
  C0004747
  C0004748
  C0005300
  C0005400
  C0005500
  C0005700
  C0005800
  C0007000
  C0270000
  C0270100
  C0320000
  C0320100
  C0320200
  C0320300
  C0320400
  C0320500
  C0328000
  C0328400
  C0328600
  C0328700
  C0338500
  C0338600
  C0571500
  C0571600
  C0571700
  C0580100
  C0580400
  C0580800
  C0581201
  C0791900
  C0792000
  C0792100
  C0799600
  C0799900
  C0800300
  C0800701
  C0991900
  C0992000
  C0992100
  C0998800
  C0999100
  C0999500
  C0999901
  C1192200
  C1192300
  C1192400
  C1198800
  C1199100
  C1199500
  C1199901
  C1500000
  C1500100
  C1500200
  C1507800
  C1508100
  C1508500
  C1508901
  C1556900
  C1557000
  C1557100
  C1564700
  C1565000
  C1565400
  C1565801
  C1792600
  C1792700
  C1792800
  C1800100
  C1800400
  C1800800
  C1801201
  C2495400
  C2495501
  C2502400
  C2502600
  C2502800
  C2503700
  C2503900
  C2523900
  C2524000
  C2530900
  C2531100
  C2531300
  C2532200
  C2532400
  C2795200
  C2795300
  C2802200
  C2802400
  C2802600
  C2803000
  C2803200
  C3103200
  C3103300
  C3110200
  C3110400
  C3110600
  C3111500
  C3111700
  C3601500
  C3601700
  C3606900
  C3607000
  C3613900
  C3614100
  C3614300
  C3615200
  C3615400
;

  label C0000100 = "ID CODE OF CHILD";
  label C0000200 = "ID CODE OF MOTHER OF CHILD";
  label C0003800 = "AGE OF CHILD (MOS) AT INT OF MOTHER 79";
  label C0003900 = "AGE OF CHILD (MOS) AT INT OF MOTHER 80";
  label C0004000 = "AGE OF CHILD (MOS) AT INT OF MOTHER 81";
  label C0004100 = "AGE OF CHILD (MOS) AT INT OF MOTHER 82";
  label C0004200 = "AGE OF CHILD (MOS) AT INT OF MOTHER 83";
  label C0004300 = "AGE OF CHILD (MOS) AT INT OF MOTHER 84";
  label C0004400 = "AGE OF CHILD (MOS) AT INT OF MOTHER 85";
  label C0004500 = "AGE OF CHILD (MOS) AT INT OF MOTHER 86";
  label C0004600 = "AGE OF CHILD (MOS) AT INT OF MOTHER 87";
  label C0004700 = "AGE OF CHILD (MOS) AT INT OF MOTHER 88";
  label C0004710 = "AGE OF CHILD (MOS) AT INT OF MOTHER 89";
  label C0004720 = "AGE OF CHILD (MOS) AT INT OF MOTHER 90";
  label C0004730 = "AGE OF CHILD (MOS) AT INT OF MOTHER 91";
  label C0004740 = "AGE OF CHILD (MOS) AT INT OF MOTHER 92";
  label C0004741 = "AGE OF CHILD (MOS) AT INT OF MOTHER 93";
  label C0004742 = "AGE OF CHILD (MOS) AT INT OF MOTHER 94";
  label C0004743 = "AGE OF CHILD (MOS) AT INT OF MOTHER 96";
  label C0004744 = "AGE OF CHILD (MOS) AT INT OF MOTHER 1998";
  label C0004745 = "AGE OF CHILD (MOS) AT INT OF MOTHER 2000";
  label C0004746 = "AGE OF CHILD (MOS) AT INT OF MOTHER 2002";
  label C0004747 = "AGE OF CHILD (MOS) AT INT OF MOTHER 2004";
  label C0004748 = "AGE OF CHILD (MOS) AT INT OF MOTHER 2006";
  label C0005300 = "RACE OF CHILD (FROM MOTHERS SCREENER 79)";
  label C0005400 = "SEX OF CHILD";
  label C0005500 = "DATE OF BIRTH OF CHILD - MONTH";
  label C0005700 = "DATE OF BIRTH OF CHILD - YEAR";
  label C0005800 = "BIRTH ORDER OF CHILD";
  label C0007000 = "AGE OF MOTHER AT BIRTH OF CHILD";
  label C0270000 = "WK # BIRTH CHILD 1/1/78-CURRENT INT DATE";
  label C0270100 = "# WKS BEF BIRTH CHLD MOTHER LEFT EMPL";
  label C0320000 = "MOTHER MAKE PRENATAL VISIT DURING PREG?";
  label C0320100 = "MONTH OF PREG OF 1ST PRENATAL CARE VISIT";
  label C0320200 = "MOTHER DRINK ALCOHOL 12 MOS B4 BRTH CHLD";
  label C0320300 = "FREQ OF ALCOHOL USE DURING PREGNANCY";
  label C0320400 = "MOTHER SMOKE DURING 12 MOS BEF BRTH CHLD";
  label C0320500 = "# CIGARETTES SMOKE DURING PREGNANCY";
  label C0328000 = "LENGTH OF GESTATION OF CHILD WKS";
  label C0328400 = "WAS CHILD DELIVERED BY C SECTION";
  label C0328600 = "WGT OF CHILD AT BIRTH IN OUNCES";
  label C0328700 = "BIRTH WGT OF CHILD 5.5 LBS OR LESS";
  label C0338500 = "CHILD BREASTFED";
  label C0338600 = "CHILD AGE (WKS) BREASTFEEDING ENDED";
  label C0571500 = "HOME: TOTAL STANDARD SCORE";
  label C0571600 = "HOME: COG STIM STANDARD SCORE";
  label C0571700 = "HOME: EMO SUPP STANDARD SCORE";
  label C0580100 = "PIAT MATH: TOTAL STD SCORE 86";
  label C0580400 = "PIAT READ REC: TOTAL STD SCORE 86";
  label C0580800 = "CHILD PPVT AGE (MOS) AT ASSESS DATE 86";
  label C0581201 = "CHILD SAMPLING WEIGHT 86 - REVISED";
  label C0791900 = "HOME: TOTAL STANDARD SCORE";
  label C0792000 = "HOME: COG STIM STANDARD SCORE";
  label C0792100 = "HOME: EMO SUPP STANDARD SCORE";
  label C0799600 = "PIAT MATH: TOTAL STD SCORE 88";
  label C0799900 = "PIAT READ REC: TOTAL STD SCORE 88";
  label C0800300 = "CHILD PPVT AGE (MOS) AT ASSESS DATE 88";
  label C0800701 = "CHILD SAMPLING WEIGHT 88 - REVISED";
  label C0991900 = "HOME: TOTAL STANDARD SCORE";
  label C0992000 = "HOME: COG STIM STANDARD SCORE";
  label C0992100 = "HOME: EMO SUPP STANDARD SCORE";
  label C0998800 = "PIAT MATH: TOTAL STD SCORE 90";
  label C0999100 = "PIAT READ REC: TOTAL STD SCORE 90";
  label C0999500 = "CHILD PPVT AGE (MOS) AT ASSESS DATE 90";
  label C0999901 = "CHILD SAMPLING WEIGHT 90 - REVISED";
  label C1192200 = "HOME: TOTAL STANDARD SCORE";
  label C1192300 = "HOME: COG STIM STANDARD SCORE";
  label C1192400 = "HOME: EMO SUPP STANDARD SCORE";
  label C1198800 = "PIAT MATH: TOTAL STANDARD SCORE - 92";
  label C1199100 = "PIAT READ REC: TOTAL STNDRD SCORE - 92";
  label C1199500 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE-92";
  label C1199901 = "CHILD SAMPLING WEIGHT 92 - REVISED";
  label C1500000 = "HOME: TOTAL STANDARD SCORE";
  label C1500100 = "HOME: COG STIM STANDARD SCORE";
  label C1500200 = "HOME: EMO SUPP STANDARD SCORE";
  label C1507800 = "PIAT MATH: TOTAL STANDARD SCORE - 94";
  label C1508100 = "PIAT READ REC: TOTAL STNDRD SCORE - 94";
  label C1508500 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE-94";
  label C1508901 = "CHILD SAMPLING WEIGHT 94 - REVISED";
  label C1556900 = "HOME: TOTAL STANDARD SCORE";
  label C1557000 = "HOME: COG STIM STANDARD SCORE";
  label C1557100 = "HOME: EMO SUPP STANDARD SCORE";
  label C1564700 = "PIAT MATH: TOTAL STANDARD SCORE 96";
  label C1565000 = "PIAT READ REC: TOTAL STNDRD SCORE 96";
  label C1565400 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE 96";
  label C1565801 = "CHILD SAMPLING WEIGHT 96 - REVISED";
  label C1792600 = "HOME: TOTAL STANDARD SCORE 1998";
  label C1792700 = "HOME: COG STIM STANDARD SCORE 1998";
  label C1792800 = "HOME: EMO SUPP STANDARD SCORE 1998";
  label C1800100 = "PIAT MATH: TOTAL STANDARD SCORE 1998";
  label C1800400 = "PIAT READ REC: TOTAL STNDRD SCORE 1998";
  label C1800800 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE 1998";
  label C1801201 = "CHILD SAMPLING WEIGHT - REVISED 1998";
  label C2495400 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE 2000";
  label C2495501 = "CHILD SAMPLING WEIGHT - REVISED 2000";
  label C2502400 = "HOME: TOTAL STANDARD SCORE 2000";
  label C2502600 = "HOME: COG STIM STANDARD SCORE 2000";
  label C2502800 = "HOME: EMO SUPP STANDARD SCORE 2000";
  label C2503700 = "PIAT MATH: TOTAL STANDARD SCORE 2000";
  label C2503900 = "PIAT READ REC: TOTAL STNDRD SCORE 2000";
  label C2523900 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE 2002";
  label C2524000 = "CHILD SAMPLING WEIGHT 2002";
  label C2530900 = "HOME: TOTAL STANDARD SCORE 2002";
  label C2531100 = "HOME: COG STIM STANDARD SCORE 2002";
  label C2531300 = "HOME: EMO SUPP STANDARD SCORE 2002";
  label C2532200 = "PIAT MATH: TOTAL STANDARD SCORE 2002";
  label C2532400 = "PIAT READ REC: TOTAL STNDRD SCORE 2002";
  label C2795200 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE 2004";
  label C2795300 = "CHILD SAMPLING WEIGHT 2004";
  label C2802200 = "HOME: TOTAL STANDARD SCORE 2004";
  label C2802400 = "HOME: COG STIM STANDARD SCORE 2004";
  label C2802600 = "HOME: EMO SUPP STANDARD SCORE 2004";
  label C2803000 = "PIAT MATH: TOTAL STANDARD SCORE 2004";
  label C2803200 = "PIAT READ REC: TOTAL STNDRD SCORE 2004";
  label C3103200 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE 2006";
  label C3103300 = "CHILD SAMPLING WEIGHT 2006";
  label C3110200 = "HOME: TOTAL STANDARD SCORE 2006";
  label C3110400 = "HOME: COG STIM STANDARD SCORE 2006";
  label C3110600 = "HOME: EMO SUPP STANDARD SCORE 2006";
  label C3111500 = "PIAT MATH: TOTAL STANDARD SCORE 2006";
  label C3111700 = "PIAT READ REC: TOTAL STNDRD SCORE 2006";
  label C3601500 = "AGE OF CHILD (MOS) AT INT OF MOTHER 2008";
  label C3601700 = "FATHER OF CHILD (IN HH) LIVE IN HH? 2008";
  label C3606900 = "PPVT AGE (IN MOS) CHILD ASSMNT DATE 2008";
  label C3607000 = "CHILD SAMPLING WEIGHT 2008";
  label C3613900 = "HOME: TOTAL STANDARD SCORE 2008";
  label C3614100 = "HOME: COG STIM STANDARD SCORE 2008";
  label C3614300 = "HOME: EMO SUPP STANDARD SCORE 2008";
  label C3615200 = "PIAT MATH: TOTAL STANDARD SCORE 2008";
  label C3615400 = "PIAT READ REC: TOTAL STNDRD SCORE 2008";

data dd.child08;
set x;
keep c0000100 c0000200 cblack chisp cfemale border agebirth weekbir prenat1
msmoke gestwks csect bw55 bweight bfeed bfwk
math56 read56 year56 vage56 home56 homec56 homee56 year56 
cmob cyob; 

**note 11,495 children in total;
cblack = 0;
if c0005300 = 2 then cblack = 1;

chisp = 0;
if c0005300 = 1 then chisp = 1;

cfemale = 0;
if c0005400 = 2 then cfemale = 1;

*birth order;
border = .;
if c0005800 gt 0 then border = c0005800;

*child month and year of birth;
cmob = .;
cyob = .;
if c0005500 gt 0 then cmob = c0005500;
if c0005700 gt 0 then cyob = c0005700;

*mother's age at birth;
agebirth = .;
if c0007000 gt 0 then agebirth = c0007000;

*week of birth, useful for employment info;
weekbir = .;
if c0270000 gt 0 then weekbir = c0270000;

*prenatal care in first trimester;
prenat1 = .;
if c0320000 = 0 then prenat1 = 0;
if (c0320100 = 1 or c0320100 = 2 or c0320100 = 3) then prenat1 = 1;
else if (c0320100 ge 4) then prenat1 = 0;

*smoke during pregnancy;
msmoke = .;
if c0320400 = 0 then msmoke = 0;
if c0320500 = 0 then msmoke = 0;
if (c0320500 ge 1) then msmoke = 1;

**weeks gestation;
gestwks = .;
if c0328000 gt 0 then gestwks = c0328000;

*delivered by c-section;
csect = .;
if c0328400 = 0 then csect = 0;
if c0328400 = 1 then csect = 1;

**birth weight;
bweight = .;
if C0328600 gt 0 then bweight = C0328600;

*birth weight less than or equal to 5.5 pounds;
bw55 = .;
if c0328700 = 0 then bw55 = 0;
if c0328700 = 1 then bw55 = 1;

*breastfeeding;
bfeed = .;
if c0338500 = 0 then bfeed = 0;
if c0338500 = 1 then bfeed = 1;

*child's age in weeks when bf ended;
bfwk = .;
if c0338600 gt 0 then bfwk = c0338600;
**fix a couple;
if (bfeed = 0 and bfwk gt 0) then bfeed = 1;

**standard home score, do separate for cognitive, emotional, and total;
**will use the home score for the year of assessment, given it starts in '86;
array home  c0571500 c0791900 c0991900 c1192200 c1500000 c1556900 c1792600
            c2502400 c2530900 c2802200 c3110200 c3613900;
array homec c0571600 c0792000 c0992000 c1192300 c1500100 c1557000 c1792700
            c2502600 c2531100 c2802400 c3110400 c3614100;
array homee c0571700 c0792100 c0992100 c1192400 c1500200 c1557100 c1792800
            c2502800 c2531300 c2802600 c3110600 c3614300;
array hyr   home86 home88 home90 home92 home94 home96 home98 home00
            home02 home04 home06 home08;
array hcyr   homec86 homec88 homec90 homec92 homec94 homec96 homec98 homec00
            homec02 homec04 homec06 homec08;
array heyr   homee86 homee88 homee90 homee92 homee94 homee96 homee98 homee00
            homee02 homee04 homee06 homee08;

*(12 rounds);
do i = 1 to 12;
   if home(i) gt 0 then hyr(i) = home(i);
   if homec(i) gt 0 then hcyr(i) = homec(i);
   if homee(i) gt 0 then heyr(i) = homee(i);
end;

**now ppvt age, piat math and piat reading recognition standard scores;
array vage c0580800 c0800300 c0999500 c1199500 c1508500 c1565400 c1800800
           c2495400 c2523900 c2795200 c3103200 c3606900;
array vageyr vage86 vage88 vage90 vage92 vage94 vage96 vage98 vage00 vage02
             vage04 vage06 vage08; 
array pmath c0580100 c0799600 c0998800 c1198800 c1507800 c1564700 c1800100 c2503700
            c2532200 c2803000 c3111500 c3615200;
array pmathyr pmath86 pmath88 pmath90 pmath92 pmath94 pmath96 pmath98 pmath00
              pmath02 pmath04 pmath06 pmath08;
array pread c0580400 c0799900 c0999100 c1199100 c1508100 c1565000 c1800400
            c2503900 c2532400 c2803200 c3111700 c3615400;
array preadyr pread86 pread88 pread90 pread92 pread94 pread96 pread98 pread00
              pread02 pread04 pread06 pread08;


do i = 1 to 12;
   if vage(i) gt 0 then vageyr(i) = vage(i)/12;
   *since age in months;
   if pmath(i) gt 0 then pmathyr(i) = pmath(i);
   if pread(i) gt 0 then preadyr(i) = pread(i);
end;

**now scores for age 5, then age 6;
math5 = .;
read5 = .;
year5 = .;
vage5 = .;
home5 = .;
homec5 = .;
homee5 = .;
do i = 1 to 12;
   *need both test scores;
      if (vageyr(i) ge 5 and vageyr(i) lt 6 and pmathyr(i) gt 0 and preadyr(i) gt 0
         and math5 = . and read5 = .) then do;
	  vage5 = vageyr(i);
      if pmathyr(i) gt 0 then math5 = pmathyr(i);
	  if preadyr(i) gt 0 then read5 = preadyr(i);
	  if hyr(i) gt 0 then home5 = hyr(i);
	  if hcyr(i) gt 0 then homec5 = hcyr(i);
	  if heyr(i) gt 0 then homee5 = heyr(i);
	  if i = 1 then year5 = 1986;
      if i = 2 then year5 = 1988;
      if i = 3 then year5 = 1990;
      if i = 4 then year5 = 1992;
      if i = 5 then year5 = 1994;
      if i = 6 then year5 = 1996;
      if i = 7 then year5 = 1998;
      if i = 8 then year5 = 2000;
      if i = 9 then year5 = 2002;
      if i = 10 then year5 = 2004;
      if i = 11 then year5 = 2006;
      if i = 12 then year5 = 2008; 
	  end;
   end;

**now age 6;
math6 = .;
read6 = .;
year6 = .;
vage6 = .;
home6 = .;
homec6 = .;
homee6 = .;
do i = 1 to 12;
   *need both test scores;
      if (vageyr(i) ge 6 and vageyr(i) lt 7 and pmathyr(i) gt 0 and preadyr(i) gt 0 
          and math6 = . and read6 = .) then do;
	  vage6 = vageyr(i);
      if pmathyr(i) gt 0 then math6 = pmathyr(i);
	  if preadyr(i) gt 0 then read6 = preadyr(i);
	  if hyr(i) gt 0 then home6 = hyr(i);
	  if hcyr(i) gt 0 then homec6 = hcyr(i);
	  if heyr(i) gt 0 then homee6 = heyr(i);
	  if i = 1 then year6 = 1986;
      if i = 2 then year6 = 1988;
      if i = 3 then year6 = 1990;
      if i = 4 then year6 = 1992;
      if i = 5 then year6 = 1994;
      if i = 6 then year6 = 1996;
      if i = 7 then year6 = 1998;
      if i = 8 then year6 = 2000;
      if i = 9 then year6 = 2002;
      if i = 10 then year6 = 2004;
      if i = 11 then year6 = 2006;
      if i = 12 then year6 = 2008; 
	  end;
   end;

**now, let's combine everything for age 5 and 6, which will use to get sample;
math56 = .;
read56 = .;
vage56 = .;
home56 = .;
homec56 = .;
homee56 = .;
year56 = .; 

if math5 gt 0 then do;
math56 = math5;
read56 = read5;
vage56 = vage5;
home56 = home5;
homec56 = homec5;
homee56 = homee5;
year56 = year5; 
end;
else if math6 gt 0 then do;
math56 = math6;
read56 = read6;
vage56 = vage6;
home56 = home6;
homec56 = homec6;
homee56 = homee6;
year56 = year6; 
end;




proc means;
run;
